package uk.co.leandro.models
{
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import org.robotlegs.mvcs.Actor;
	import uk.co.leandro.events.TimeEvent;
	
	public class GameModel extends Actor
	{
		private var timer:Timer;
		private var countDown:int;
		
		public function GameModel()
		{
			super();
		}
		
		public function start():void
		{
			countDown = 60;
			timer = new Timer(1000);
			timer.addEventListener(TimerEvent.TIMER, timerHandler);
			timer.start();
		}
		
		public function stop():void
		{
			timer.removeEventListener(TimerEvent.TIMER, timerHandler);
			timer.stop();
		}
		
		private function timerHandler(event:TimerEvent=null):void
		{
			var e:TimeEvent = new TimeEvent(TimeEvent.TICK);
			e.countDown = countDown--;
			dispatch(e);
		}
	}
}